/**
 * Created by Administrator on 2021/10/19.
 */


//通过页面加载事件获得所有标签
window.onload=function () {
    //获得DOM对象
    result=document.getElementById("result");
    seconds=document.getElementsByClassName("second");
    //当页面加载完成时需要执行的代码

}

//其它函数：通过用户触发的事件执行这些函数
//o:1-打开；2-隐藏
//obj:行号
function showMenu(o,obj) {
    if(o==1) {
        //打开隐藏层 display:none/block
        result.style.display = "block";
        result.innerHTML="";
        //向服务器发起请求
        //请求地址: /catalog?param=byLevel1&line=行号
        //alert(obj);
        var xhr = new XMLHttpRequest();//创建对象
        //确定请求方式和地址
        xhr.open("get", "/catalog?param=byLevel1&line=" + obj);
        //发送请求
        xhr.send();

        //接收服务器的响应结果 0 1 2 3 4
        xhr.onreadystatechange = function () {
            //说明请求处理完成
            if (xhr.readyState == 4) {
                //判断响应状态
                if (xhr.status == 200) {
                    //取出服务器发回的值
                    var res = JSON.parse(xhr.responseText);//将接收到的字符串转为引用类型  "{name:'hello'}"
                    //console.log(typeof(res));//判断数据类型
                    for (var i in res) {
                        //seconds[i].innerHTML=res[i].cname;
                        /*
                         <div class="row line">
                             <div class="col-md-2 second">2</div>
                             <div class="col-md-10 third">3</div>
                         </div>
                         */
                        var div_row=document.createElement("div");//创建标签
                        div_row.style.width="800px";//用JS实现CSS设置
                        div_row.style.height="50px";

                        var div_second=document.createElement("div");
                        div_second.style.width="100px";
                        div_second.style.float="left";
                        div_second.innerHTML="<a href='goods?cid2="+res[i].c2.cid+"'>"+res[i].c2.cname+"</a>";//catalogVOs.getC2().getCname()
                        div_row.appendChild(div_second);//添加到父节点

                        var div_third=document.createElement("div");
                        div_third.style.width="680px";
                        div_third.style.float="left";
                        //c3s--->[]
                        var c3s_val=res[i].c3s;
                        for(var j in c3s_val){
                            div_third.innerHTML+= "<a href='goods?cid3="+c3s_val[j].cid+"'>"+c3s_val[j].cname+"</a>&nbsp;&nbsp;&nbsp;&nbsp;";
                        }
                        div_row.appendChild(div_third);//添加到父节点

                        result.appendChild(div_row);
                    }
                }
            }
        }
    }else if(o==2){
       result.style.display="none";
    }

}